home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 13 The Compute Shader / Blur / BlurFilter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  2.1 KB  |  78 lines

  1. //***************************************************************************************
  2. // BlurFilter.h by Frank Luna (C) 2011 All Rights Reserved.
  3. //
  4. // Performs a blur operation on the topmost mip level of an input texture.
  5. //***************************************************************************************
  6.  
  7. #pragma once
  8.  
  9. #include "../../Common/d3dUtil.h"
  10.  
  11. class BlurFilter
  12. {
  13. public:
  14.     ///<summary>
  15.     /// The width and height should match the dimensions of the input texture to blur.
  16.     /// Recreate when the screen is resized. 
  17.     ///</summary>
  18.     BlurFilter(ID3D12Device* device, 
  19.         UINT width, UINT height,
  20.         DXGI_FORMAT format);
  21.         
  22.     BlurFilter(const BlurFilter& rhs)=delete;
  23.     BlurFilter& operator=(const BlurFilter& rhs)=delete;
  24.     ~BlurFilter()=default;
  25.  
  26.     ID3D12Resource* Output();
  27.  
  28.     void BuildDescriptors(
  29.         CD3DX12_CPU_DESCRIPTOR_HANDLE hCpuDescriptor, 
  30.         CD3DX12_GPU_DESCRIPTOR_HANDLE hGpuDescriptor,
  31.         UINT descriptorSize);
  32.  
  33.     void OnResize(UINT newWidth, UINT newHeight);
  34.  
  35.     ///<summary>
  36.     /// Blurs the input texture blurCount times.
  37.     ///</summary>
  38.     void Execute(
  39.         ID3D12GraphicsCommandList* cmdList, 
  40.         ID3D12RootSignature* rootSig,
  41.         ID3D12PipelineState* horzBlurPSO,
  42.         ID3D12PipelineState* vertBlurPSO,
  43.         ID3D12Resource* input,         
  44.         int blurCount);
  45.  
  46. private:
  47.     std::vector<float> CalcGaussWeights(float sigma);
  48.  
  49.     void BuildDescriptors();
  50.     void BuildResources();
  51.  
  52. private:
  53.  
  54.     const int MaxBlurRadius = 5;
  55.  
  56.     ID3D12Device* md3dDevice = nullptr;
  57.  
  58.     UINT mWidth = 0;
  59.     UINT mHeight = 0;
  60.     DXGI_FORMAT mFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
  61.  
  62.     CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur0CpuSrv;
  63.     CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur0CpuUav;
  64.  
  65.     CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur1CpuSrv;
  66.     CD3DX12_CPU_DESCRIPTOR_HANDLE mBlur1CpuUav;
  67.  
  68.     CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur0GpuSrv;
  69.     CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur0GpuUav;
  70.  
  71.     CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur1GpuSrv;
  72.     CD3DX12_GPU_DESCRIPTOR_HANDLE mBlur1GpuUav;
  73.  
  74.     // Two for ping-ponging the textures.
  75.     Microsoft::WRL::ComPtr<ID3D12Resource> mBlurMap0 = nullptr;
  76.     Microsoft::WRL::ComPtr<ID3D12Resource> mBlurMap1 = nullptr;
  77. };
  78.